﻿@{
    ViewBag.Title = "FlowersIndex";
    Layout = "~/Views/Users/Index.cshtml";
}

<script src="~/Scripts/jquery-1.8.2.min.js"></script>
<link href="~/css/bootstrap.css" rel="stylesheet" />
<script src="~/js/bootstrap.min.js"></script>
<script src="~/js/jquery.min.js"></script>

<form action="/Flowers/FlowersIndex" method="post">
    花卉名称:<input id="txtname" type="text" name="FlowersName" />&emsp;<input id="Submit1" type="submit" value="查询" />
</form>
<table class="table table-responsive">
    <tr>
        <td>编号</td>
        <td>花卉名称</td>
        <td>库存</td>
        <td>进货单价</td>
        <td>销售单价</td>
        <td>状态</td>
        <td>图片</td>
        <td>添加时间</td>
        <td>操作</td>
    </tr>
    <tbody id="tbo">
        @foreach (var i in ViewBag.list)
        {
            <tr>
                <td>@i.FlowersID</td>
                <td>@i.FlowersName</td>
                <td>@i.FlowersStock</td>
                <td>@i.PurchasePrice</td>
                <td>@i.Sales_unit_price</td>
                <td>@(i.FlowerState == 1 ? "上架" : "下架")</td>
                <td><img src="@i.FlowersImg" alt="Alternate Text" style="width:40px;height:40px;" /></td>
                <td>@i.FlowersAddTime</td>
                <td><input type='button' value='上架' class='btn btn-success' onclick='Full(@i.FlowersID)' /><input type='button' value='下架' class='btn btn-success' onclick='Del(@i.FlowersID)' /><input type='button' value='编辑' class='btn btn-success' onclick="return location.href = '/Flowers/fantian/@i.FlowersID'"/></td>
            </tr>
        }
    </tbody>
</table>

<script>

    function Full(id) {
        $.ajax({
            type: "post",
            url: "/Flowers/FlowersFull",
            data: { FlowersID: id },

            success: function (obj) {
                if (obj > 0) {
                    alert("上架成功");
                    location.href = '/Flowers/FlowersIndex';
                }
                else {
                    alert("失败!");
                }
            }
        })
    }
    function Del(id) {

        $.ajax({
            type: "post",
            url: "/Flowers/FlowersDel",
            data: { FlowersID: id },

            success: function (obj) {
                if (obj > 0) {
                    alert("下架成功");
                    location.href = '/Flowers/FlowersIndex';
                }
                else {
                    alert("失败!");
                }
            }
        })
    }
</script>